package cn.itsource.mq.receiver;

import cn.itsource.mq.config.RabbitmqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class Receiver {
    //消费短信
    @RabbitListener(queues = RabbitmqConfig.QUEUE_INFORM_SMS)
    public void smsHandler(String msgStr , Message message, Channel channel) throws IOException {
        System.out.println("SMS收到消息："+msgStr);
        System.out.println("message.getBody()："+new String(message.getBody()));
        System.out.println("getDeliveryTag："+message.getMessageProperties().getDeliveryTag());
        System.out.println("getMessageCount："+message.getMessageProperties().getMessageCount());
        System.out.println("消费结束");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
    //消费邮件
    @RabbitListener(queues = RabbitmqConfig.QUEUE_INFORM_EMAIL)
    public void emailHandler(String msgStr , Message message, Channel channel) throws IOException {
        System.out.println("email收到消息："+msgStr);
        System.out.println("message.getBody()："+new String(message.getBody()));
        System.out.println("getDeliveryTag："+message.getMessageProperties().getDeliveryTag());
        System.out.println("getMessageCount："+message.getMessageProperties().getMessageCount());
        System.out.println("消费结束");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


}
